package com.chainshop.procurement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;
import com.chainshop.procurement.domain.ProcurementInfoList;
import com.chainshop.procurement.service.IProcurementInfoListService;
import com.chainshop.common.utils.poi.ExcelUtil;
import com.chainshop.common.core.page.TableDataInfo;

/**
 * 存储采购信息清单的Controller
 * 
 * @author zzd
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/procurement/procurement")
public class ProcurementInfoListController extends BaseController
{
    @Autowired
    private IProcurementInfoListService procurementInfoListService;

    /**
     * 查询存储采购信息清单的列表
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcurementInfoList procurementInfoList)
    {
        startPage();
        List<ProcurementInfoList> list = procurementInfoListService.selectProcurementInfoListList(procurementInfoList);
        return getDataTable(list);
    }

    /**
     * 导出存储采购信息清单的列表
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:export')")
    @Log(title = "存储采购信息清单的", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcurementInfoList procurementInfoList)
    {
        List<ProcurementInfoList> list = procurementInfoListService.selectProcurementInfoListList(procurementInfoList);
        ExcelUtil<ProcurementInfoList> util = new ExcelUtil<ProcurementInfoList>(ProcurementInfoList.class);
        util.exportExcel(response, list, "存储采购信息清单的数据");
    }

    /**
     * 获取存储采购信息清单的详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:query')")
    @GetMapping(value = "/{listId}")
    public AjaxResult getInfo(@PathVariable("listId") String listId)
    {
        return success(procurementInfoListService.selectProcurementInfoListByListId(listId));
    }

    /**
     * 新增存储采购信息清单的
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:add')")
    @Log(title = "存储采购信息清单的", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcurementInfoList procurementInfoList)
    {
        return toAjax(procurementInfoListService.insertProcurementInfoList(procurementInfoList));
    }

    /**
     * 修改存储采购信息清单的
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:edit')")
    @Log(title = "存储采购信息清单的", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcurementInfoList procurementInfoList)
    {
        return toAjax(procurementInfoListService.updateProcurementInfoList(procurementInfoList));
    }

    /**
     * 删除存储采购信息清单的
     */
    @PreAuthorize("@ss.hasPermi('procurement:procurement:remove')")
    @Log(title = "存储采购信息清单的", businessType = BusinessType.DELETE)
	@DeleteMapping("/{listIds}")
    public AjaxResult remove(@PathVariable String[] listIds)
    {
        return toAjax(procurementInfoListService.deleteProcurementInfoListByListIds(listIds));
    }

    @GetMapping("/getTree")
    public AjaxResult getTree(){
        return success(procurementInfoListService.getTree());
    }

    @GetMapping("/getVariantsProduct/{id}")
    public AjaxResult getVariantsProduct(@PathVariable String id){
        return success(procurementInfoListService.getVariantsProduct(id));
    }
}
